#include <QtGui>
#include "QtStra_StrategyInfo.h"


QtStraStrategyInfo::QtStraStrategyInfo(QWidget * parent): QWidget(parent)
{

	indexLabel = new QLabel(tr("index:"));
	indexLineEdit = new QLineEdit;
	indexLineEdit->setEnabled(false);
	tickcntLabel = new QLabel(tr("tickcnt:"));
	tickcntLineEdit = new QLineEdit;
	tickcntLineEdit->setEnabled(false);
	starttimeLabel = new QLabel(tr("starttime:"));
	starttimeLineEdit = new QLineEdit;
	starttimeLineEdit->setEnabled(false);
	curtimeLabel = new QLabel(tr("endtime:"));
	curtimeLineEdit = new QLineEdit;
	curtimeLineEdit->setEnabled(false);
	openLabel = new QLabel(tr("open:"));
	openLineEdit = new QLineEdit;
	openLineEdit->setEnabled(false);
	highLabel = new QLabel(tr("high:"));
	highLineEdit = new QLineEdit;
	highLineEdit->setEnabled(false);
	lowLabel = new QLabel(tr("low:"));
	lowLineEdit = new QLineEdit;
	lowLineEdit->setEnabled(false);
	closeLabel = new QLabel(tr("close:"));
	closeLineEdit = new QLineEdit;
	closeLineEdit->setEnabled(false);
	QSpacerItem* spacerItem = new QSpacerItem(QSizePolicy::Minimum, QSizePolicy::ExpandFlag);


	QGridLayout *barLayout = new QGridLayout;
	barLayout->addWidget(indexLabel, 0, 0);
	barLayout->addWidget(indexLineEdit, 0, 1);
	barLayout->addWidget(tickcntLabel, 0, 2);
	barLayout->addWidget(tickcntLineEdit, 0, 3);
	barLayout->addWidget(starttimeLabel, 1, 0);
	barLayout->addWidget(starttimeLineEdit, 1, 1);
	barLayout->addWidget(curtimeLabel, 1, 2);
	barLayout->addWidget(curtimeLineEdit, 1, 3);
	barLayout->addWidget(openLabel, 2, 0);
	barLayout->addWidget(openLineEdit, 2, 1);
	barLayout->addWidget(highLabel, 2, 2);
	barLayout->addWidget(highLineEdit, 2, 3);
	barLayout->addWidget(lowLabel, 3, 0);
	barLayout->addWidget(lowLineEdit, 3, 1);
	barLayout->addWidget(closeLabel, 3, 2);
	barLayout->addWidget(closeLineEdit, 3, 3);
	barLayout->addItem(spacerItem, 4, 0, 4, 1);


	//QWidget* barWidget = new QWidget;
	setLayout(barLayout);


	

}


void QtStraStrategyInfo::ShowInfo(const BarData& showbar)
{

	indexLineEdit->setText(QString::number(showbar.index));
	tickcntLineEdit->setText(QString::number(showbar.tickcnt));
	
	char starttime[50] = {0};
	sprintf(starttime, "%d:%d:%d.%d-%d-%d-%d", showbar.starttime.wHour, showbar.starttime.wMinute, showbar.starttime.wSecond, showbar.starttime.wMilliseconds,
		showbar.starttime.wMonth, showbar.starttime.wDay, showbar.starttime.wYear);
	starttimeLineEdit->setText(QString(starttime));

	char curtime[50] = {0};
	sprintf(curtime, "%d:%d:%d.%d-%d-%d-%d", showbar.curtime.wHour, showbar.curtime.wMinute, showbar.curtime.wSecond, showbar.curtime.wMilliseconds,
		showbar.curtime.wMonth, showbar.curtime.wDay, showbar.curtime.wYear);
	curtimeLineEdit->setText(QString(curtime));


	
	openLineEdit->setText(QString::number(showbar.open));
	highLineEdit->setText(QString::number(showbar.high));
	lowLineEdit->setText(QString::number(showbar.low));
	closeLineEdit->setText(QString::number(showbar.close));
}

void QtStraStrategyInfo::ClearInfo()
{
	indexLineEdit->clear();
	tickcntLineEdit->clear();
	starttimeLineEdit->clear();
	curtimeLineEdit->clear();
	openLineEdit->clear();
	highLineEdit->clear();
	lowLineEdit->clear();
	closeLineEdit->clear();
}